package com.ttg.common.utils;


import com.ttg.common.exception.BaseException;
import lombok.extern.slf4j.Slf4j;

/**
 * @author ZQ
 * @version 1.0
 * @Description
 * @date 2021/3/1 15:26
 */
@Slf4j
public class RequestParamsManager {

    public static <T>T transformRequestParam(String data,Class<T> clazz){
        T reqDto = null;
        try {
            if (null == data || "null".equals(data)) {
                reqDto = clazz.newInstance();
            } else {
                reqDto = JsonUtils.jsonToObject(data, clazz);
            }
        } catch (Exception e) {
            log.error("参数转换异常",e);
            throw new BaseException("请求参数格式错误");
        }
        if(null == reqDto){
            throw new BaseException("参数为空");
        }
        return reqDto;
    }
}
